﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");

		termId = event.getArg("TermID", event.getArg("TID"));
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");
		
		event.setArg("pageTitle", "教学任务安排 - 教学任务 - 选课学生名单");
		
		currentTab = event.getArg("TabID", "labStudent");
		
		passArgs = structNew();
		structInsert(passArgs, "TID", termId, true);
		
		targetArgs = structNew();
		structInsert(targetArgs, "TID", termId, true);
		structInsert(targetArgs, "TSK", taskId, true);
		structInsert(targetArgs, "TT", taskType, true);
		
		/* 课程相关信息 */
		switch (taskType) {
			
			case "C":
				
				sql = "SELECT 
							t_course.course_name, 
							t_course.course_credit, 
							t_course.period, 
							t_course.period_theory, 
							t_institute.institute_name, 
							t_course_catalog.cat_name, 
							CASE WHEN t_course.intro IS NULL THEN '-' ELSE t_course.intro END intro, 
							CASE WHEN t_course.reference_books IS NULL THEN '-' ELSE t_course.reference_books END reference_books, 
							CASE WHEN t_course.course_english IS NULL THEN '-' ELSE t_course.course_english END course_english, 
							t_course.cid, 
							t_course.course_code, 
							SUBSTR(a.task_prop, 3, 1) sub_taskProp   
						FROM 
							t_common_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
							INNER JOIN t_course_catalog ON t_course_catalog.cat_id = t_course.cat_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;

			case "P":

				sql = "SELECT 
							t_course.course_name, 
							t_course.course_credit, 
							t_course.period, 
							t_course.period_theory, 
							t_institute.institute_name, 
							t_course_catalog.cat_name, 
							CASE WHEN t_course.intro IS NULL THEN '-' ELSE t_course.intro END intro, 
							CASE WHEN t_course.reference_books IS NULL THEN '-' ELSE t_course.reference_books END reference_books, 
							CASE WHEN t_course.course_english IS NULL THEN '-' ELSE t_course.course_english END course_english, 
							t_course.cid, 
							t_course.course_code, 
							SUBSTR(a.task_prop, 3, 1) sub_taskProp 
						FROM 
							t_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
							INNER JOIN t_course_catalog ON t_course_catalog.cat_id = t_course.cat_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;
			
			case "T":

				sql = "SELECT 
							t_course.course_name, 
							t_course.course_credit, 
							t_course.period, 
							t_course.period_theory, 
							t_institute.institute_name, 
							t_course_catalog.cat_name, 
							CASE WHEN t_course.intro IS NULL THEN '-' ELSE t_course.intro END intro, 
							CASE WHEN t_course.reference_books IS NULL THEN '-' ELSE t_course.reference_books END reference_books, 
							CASE WHEN t_course.course_english IS NULL THEN '-' ELSE t_course.course_english END course_english, 
							t_course.cid, 
							t_course.course_code, 
							SUBSTR(a.task_prop, 3, 1) sub_taskProp   
						FROM 
							t_sport_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
							INNER JOIN t_course_catalog ON t_course_catalog.cat_id = t_course.cat_id 
						WHERE 
							a.tsk_id = :taskId ";
				break;
			
			case "R":

				 sql = "SELECT 
							t_course.course_name, 
							t_course.course_credit, 
							t_course.period, 
							t_course.period_theory, 
							t_institute.institute_name, 
							t_course_catalog.cat_name, 
							CASE WHEN t_course.intro IS NULL THEN '-' ELSE t_course.intro END intro, 
							CASE WHEN t_course.reference_books IS NULL THEN '-' ELSE t_course.reference_books END reference_books, 
							CASE WHEN t_course.course_english IS NULL THEN '-' ELSE t_course.course_english END course_english, 
							t_course.cid, 
							t_course.course_code   
						FROM 
							t_reopen_task a 
							INNER JOIN t_course ON t_course.cid = a.cid 
							INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
							INNER JOIN t_course_catalog ON t_course_catalog.cat_id = t_course.cat_id 
						WHERE 
							a.tsk_id = :taskId ";				
				break;
			
		}
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
		rs_course = queryObj.execute( sql=sql ).getResult();
		
		/* 选课数据 */
		sql = "SELECT 
					t_student.stu_id, 
					t_student.stu_name, 
					t_class.cls_name, 
					t_class.grade, 
					t_institute.institute_short, 
					t_student_course.st, 
					t_student_course.choose_time, 
					t_student_course.retaking, 
					t_student_course.choose_prop, 
					t_student_course.retaking, 
					t_student_course.scc_id, 
					t_student_course.cid, 
					t_student_course.task_type, 
					t_student_course.task_id 
				FROM 
					t_student_course 
					INNER JOIN t_student ON t_student.stu_id = t_student_course.stu_id 
					INNER JOIN t_class ON t_class.cls_id = t_student.cls_id 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
					INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					t_student_course.task_id = :taskId 
				ORDER BY 
					t_student.stu_id ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
		rs_chooser = queryObj.execute( sql=sql ).getResult();
	
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('reviewTask', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学任务调整</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#rs_course.course_name#</cfoutput> - <cfoutput>#rs_course.cat_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labCourse">class="active"</cfif> id="labCourse" tabTarget="Course">课程介绍</span>
						<span <cfif currentTab eq "labStudent">class="active"</cfif> id="labStudent" tabTarget="Student">选课学生名单</span>
					</div>
				</div>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Course" class="tabContent">
					
					<div class="noticeBlock">
						<h3>《<cfoutput>#rs_course.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_course.institute_name#</cfoutput></h3>
						<p>
							<span class="img icon16x16 message"></span>
							<cfif rs_course.course_code neq "-">课程号 <em><cfoutput>#rs_course.course_code#</cfoutput></em></cfif>
							总学时 <em><cfoutput>#rs_course.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_course.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_course.course_credit, '_.00')#</cfoutput></em>
							英文课程名 <em><cfif rs_course.course_english eq "-">None<cfelse><cfoutput>#rs_course.course_english#</cfoutput></cfif></em>
						</p>
					</div>
					
					<div id="courseInfo">

						<div class="noticeBlock">
							<h2>课程简介</h2>
							
							<cfif rs_course.intro neq "-">
								<cfoutput>#stringAdvice.XHTMLParagraphFormat(rs_course.intro)#</cfoutput>
								<cfelse>
								暂无
							</cfif>
						</div>
					
						<div class="noticeBlock">
							<h2>参考书籍</h2>
							
							<cfif rs_course.reference_books neq "-">
								<cfoutput>#stringAdvice.XHTMLParagraphFormat(rs_course.reference_books)#</cfoutput>
								<cfelse>
								暂无
							</cfif>
						</div>
					</div>
					
				</div>
				
				<div id="Student" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('applyWizardByCourse', targetArgs)#</cfoutput>"><i class="mrs img btnAddWhite"></i><span class="uiButtonText">添加选课学生</span></a>
							<cfif rs_chooser.recordCount>
								<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('chooserPrint', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印选课名单</span></a>
								<a class="uiButton" href="<cfoutput>#buildURL('chooserDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载电子表格</span></a>
							</cfif>
						</div>
						<h3>《<cfoutput>#rs_course.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_course.institute_name#</cfoutput></h3>
						<p>
							<span class="img icon16x16 message"></span>
							<cfif rs_course.course_code neq "-">课程号 <em><cfoutput>#rs_course.course_code#</cfoutput></em></cfif>
							总学时 <em><cfoutput>#rs_course.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_course.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_course.course_credit, '_.00')#</cfoutput></em>
						</p>
					</div>
					
					<div id="taskChooser">
						<!--- 显示选课记录--->
						<!-- taskChooser -->
						<cfoutput>#event.getArg("taskChooser")#</cfoutput>
						<!-- /taskChooser -->
					</div>

				</div>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					function removeTask(chooserId, courseId, stuId, termId, taskType, taskId) {
							
						/* 显示阻挡信息 */
						$.blockUI({ 
									message: '正在删除课程...',
									css: { 
											'width': '16%',
											'left': '42%',
											'border': 'none', 
											'padding': '15px 5px', 
											'backgroundColor': '#090', 
											'border-radius': '4px', 
											'opacity': .8, 
											'color': '#fff',
											'cursor': null
											},
									overlayCSS: {
											'backgroundColor': '#000', 
											'opacity': .1 ,
											'cursor': null
											}
									}); 
						
						/* 异步提交退课数据 */
						$.post(
								"<cfoutput>#buildURL('apiRemoveTask')#</cfoutput>", 
								{
									'STU': stuId,
									'TID': termId,
									'CID' : courseId,
									'TSK': taskId,
									'TT' : taskType,
									'SCC' : chooserId,
									'seed': (new Date()).getTime()
								},
								function(data) {
										
									//$("#out").html(data);
									result = $.parseJSON(data);
										
									if ( result.success ) {

										/* 更新学生选课记录 */
										$.post(
												"<cfoutput>#buildURL('apiTaskChoosen')#</cfoutput>", 
												{
													'TID': '<cfoutput>#termId#</cfoutput>',
													'TSK': '<cfoutput>#taskId#</cfoutput>',
													'TT': '<cfoutput>#taskType#</cfoutput>',
													'seed': (new Date()).getTime()
												},
												function(tableData) {
												
													$("#taskChooser").html(tableData);
														
													/* 取消阻挡 */
													$.unblockUI();
														
												});
									}
									else {
										alert(result.reason);
										/* 取消阻挡 */
										$.unblockUI();
									}
										
								});
							
					}
					// -->
					//]]>
				</script>
				
			</div>
		</li>
	</ul>
</div>





